{% extends "basic.html" %}
{% block mainbody %}
{% load mytags %}
<style>
/* Custom Styles */
td{padding:2px 0px;}
</style>
<form id="form1" class="form-horizontal" role="form" method="POST" action="/borrow/prizeticket/" style="padding-bottom:100px;">
  {% csrf_token %}
  
  <input type="hidden" name="borrow_id" value="{{ info.id }}"/>
  <h5 class="text-center">{{ info.borrow_name }}</h5>
  <table class="table">
    {% for vo in list %}
    <tr>
      <td>
        <table style="margin:20px auto 0px auto;">
          <tr>
            <input type="hidden" name="id" value="{{ vo.id }}" readonly="readonly"  maxlength="10"/>
            <td>{% if info.is_immediately_loan == "1" %}订单金额{% else %}总投资金额{% endif %}：</td>
            <td>
              <input type="number" name="invest_min_money" value="{{ vo.invest_min_money|toint }}" style="width:100px;line-height:24px;text-align:center;" maxlength="10"/>
              -
              <input type="number" name="invest_max_money" value="{{ vo.invest_max_money|toint }}" style="width:100px;line-height:24px;text-align:center;" maxlength="10"/>
              元
            </td>
          </tr>
          <tr>
            <td>计算类型：</td>
            <td>
              {% for vo2 in borrow_prize_calculation_type %}
                <label class="checkbox-inline"><input type="radio" name="calculation_type{{ vo.id }}" value="{{ vo2.k }}" {% if vo2.k|stringToInt == vo.calculation_type|stringToInt %}checked{% endif %}>{{ vo2.v }}</label>
              {% endfor %}
            </td>
          </tr>
          <tr>
          <tr>
            <td>奖励最高金额：</td>
            <td>
              <div class="input-group">
                <span class="input-group-addon">¥</span>
                <input type="text" class="form-control" name="prize_max_money" value="{{ vo.prize_max_money|toint }}">
                <span class="input-group-addon">元</span>
              </div>
            </td>
          </tr>
          <tr>
            <td>奖励值：</td>
            <td>
              <div class="input-group">
                <span class="input-group-addon">V</span>
                <input type="text" class="form-control" name="prize_value" value="{{ vo.prize_value|tofloat }}">
                <span class="input-group-addon">元/%</span>
              </div>
            </td>
          </tr>
          <tr>
            <td>起投金额：</td>
            <td>
              <div class="input-group">
                <span class="input-group-addon">¥</span>
                <input type="number" class="form-control" name="order_invest_min_money" value="{{ vo.order_invest_min_money|toint }}">
                <span class="input-group-addon">元</span>
              </div>
            </td>
          </tr>
          <tr>
            <td>起投天数：</td>
            <td>
              <div class="input-group">
                <span class="input-group-addon">D</span>
                <input type="number" class="form-control" name="invest_min_duration" value="{{ vo.invest_min_duration|toint }}">
                <span class="input-group-addon">天</span>
              </div>
            </td>
          </tr>
          <tr>
            <td>可用开始时间：</td>
            <td>
              <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>
                <input type="text" name="ttstamp~available_start_dt" class="Wdate form-control" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});document.activeElement.blur();" style="height:30px;" value="{{ vo.available_start_dt|timestampToDatetime }}"/>
              </div>
            </td>
          </tr>
          <tr>
            <td>过期类型：</td>
            <td>
              {% for vo2 in available_end_type_arr %}
                <label class="checkbox-inline"><input type="radio" name="available_end_type{{ vo.id }}" value="{{ vo2.k }}" {% if vo2.k|stringToInt == vo.available_end_type|stringToInt %}checked{% endif %}>{{ vo2.v }}</label>
              {% endfor %}
            </td>
          </tr>
          <tr>
            <td>加天数：</td>
            <td>
              <div class="input-group">
                <span class="input-group-addon">D</span>
                <input type="number" class="form-control" name="valid_days" value="{{ vo.valid_days|toint }}">
                <span class="input-group-addon">天</span>
              </div>
            </td>
          </tr>
          <tr>
            <td>过期时间：</td>
            <td>
              <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>
                <input type="text" name="ttstamp~available_end_dt" class="Wdate form-control" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});document.activeElement.blur();" style="height:30px;" value="{{ vo.available_end_dt|timestampToDatetime }}"/>
              </div>
            </td>
          </tr>
          <tr>
            <td></td>
            <td><a href="javascript:deleted('/borrow/prize/del/?id={{ vo.id }}');">删除</a></td>
          </tr>
        </table>
      </td>
    </td>
    {% endfor %}
    <tr class="text-center" style="background:#FFF;" id="last_tr">
      <td>
        <button type="button" class="form-group" id="add_btn">添加</button>
      </td>
    </tr>
  </table>
  
  <div id="btn_submit_fixed_bootom" class="form-group navbar-fixed-bottom" style="margin:5px;">
    <button type="submit" class="btn btn-primary btn-lg btn-block">保存</button>
  </div>
  <script type="text/javascript">document.write( '<style>div#btn_submit_fixed_bootom{visibility:hidden}@media(min-height:' + ($( window ).height() - 10) + 'px){div#btn_submit_fixed_bootom{visibility:visible}}</style>' );</script>
</form>
<script type="text/javascript">
  var i = 99999999;
  $("#add_btn").click(function(){
    var html = '<tr id="add_tr_'+i+'"><td class="active"><table style="margin:20px auto 0px auto;">';
    var new_html="";
    //
    {% if info.is_immediately_loan == "1" %}
      html +='<tr><td>订单金额：</td>';
    {% else %}
      html +='<tr><td>总投资金额：</td>';
    {% endif %}
    new_html ='<input type="number" name="invest_min_money" style="width:100px;line-height:24px;text-align:center;" maxlength="10"/>';
    new_html +='-';
    new_html +='<input type="number" name="invest_max_money" style="width:100px;line-height:24px;text-align:center;" maxlength="10"/>';
    new_html +='元';
    html += '<td>'+new_html+'</td>';
    html +='</td></tr>';
    //
    html +='<tr><td>计算类型：</td>';
    new_html='<label class="checkbox-inline"><input type="radio" name="calculation_type'+i+'" value="1" checked="checked"/>固定金额</label>';
		new_html+='<label class="checkbox-inline"><input type="radio" name="calculation_type'+i+'" value="2"/>加息(百分比)</label>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html +='<tr><td>奖励最高金额：</td>';
    new_html='<div class="input-group">';
    new_html+='<span class="input-group-addon">¥</span>';
    new_html+='<input type="text" class="form-control" name="prize_max_money">';
    new_html+='<span class="input-group-addon">元</span>';
    new_html+='</div>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html +='<tr><td>奖励值：</td>';
    new_html='<div class="input-group">';
    new_html+='<span class="input-group-addon">V</span>';
    new_html+='<input type="text" class="form-control" name="prize_value">';
    new_html+='<span class="input-group-addon">元/%</span>';
    new_html+='</div>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html +='<tr><td>起投金额：</td>';
    new_html='<div class="input-group">';
    new_html+='<span class="input-group-addon">¥</span>';
    new_html+='<input type="number" class="form-control" name="order_invest_min_money">';
    new_html+='<span class="input-group-addon">元</span>';
    new_html+='</div>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html +='<tr><td>起投天数：</td>';
    new_html='<div class="input-group">';
    new_html+='<span class="input-group-addon">D</span>';
    new_html+='<input type="number" class="form-control" name="invest_min_duration">';
    new_html+='<span class="input-group-addon">天</span>';
    new_html+='</div>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html +='<tr><td>可用开始时间：</td>';
    new_html='<div class="input-group">';
    new_html+='<span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>';
    new_html+='<input type="text" name="ttstamp~available_start_dt" class="Wdate form-control" onfocus="WdatePicker({dateFmt:\'yyyy-MM-dd HH:mm:ss\'});document.activeElement.blur();" style="height:30px;"/>';
    new_html+='</div>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html +='<tr><td>过期类型：</td>';
    new_html='<label class="checkbox-inline"><input type="radio" name="available_end_type'+i+'" value="0" checked="checked"/>加天数</label>';
		new_html+='<label class="checkbox-inline"><input type="radio" name="available_end_type'+i+'" value="1"/>指定时间</label>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html +='<tr><td>加天数：</td>';
    new_html='<div class="input-group">';
    new_html+='<span class="input-group-addon">D</span>';
    new_html+='<input type="number" class="form-control" name="valid_days">';
    new_html+='<span class="input-group-addon">天</span>';
    new_html+='</div>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html +='<tr><td>过期时间：</td>';
    new_html='<div class="input-group">';
    new_html+='<span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>';
    new_html+='<input type="text" name="ttstamp~available_end_dt" class="Wdate form-control" onfocus="WdatePicker({dateFmt:\'yyyy-MM-dd HH:mm:ss\'});document.activeElement.blur();" style="height:30px;"/>';
    new_html+='</div>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html +='<tr><td></td>';
    new_html='<a href="javascript:void(0)" do="newdatadel" i="'+i+'">删除</a>';
    html += '<td>'+new_html+'</td>';
    html +='</tr>';
    //
    html+='<input type="hidden" name="id" value="-'+i+'" readonly="readonly"  maxlength="10"/>';
    html += '</table></td></tr>'
    $("#last_tr").before(html);
    i++;
  });
  $("a[do='newdatadel']").live("click", function(){
    var i=$(this).attr("i");
    $("tr#add_tr_"+i).remove();
  });
</script>
<script type="text/javascript">
$(document).ready(function(){
  $("#form1").submit(function(){
    //return true;
    var data=$(this).serialize();
    var url=$(this).attr("action");
    var tips=art.dialog.tips("正在提交……");
    
    $.ajax({
      async:false,
      type:'POST',
      url:url,
      data:data,
      success:function(rsObj){
        if(rsObj.response_code=="1"){
          art.dialog({
            content:rsObj.response_message,
            cancelVal:'继续编辑',
            cancel:function(){
              tips.close();
              window.location.reload();
            },
            okVal:'返回',
            ok:function(){
              javascript:window.history.go(-1);
            }
          });
        }else{
          art.dialog.alert(rsObj.response_message);
        }
      },
      cache:false
    });
    return false;
  });
});
</script>
<script type="text/javascript">
	function deleted(url){
		art.dialog({
			id:'open',
			lock:true,
			content:'确定删除吗？',
			icon:'question',
			okVal:'确定删除',
			ok:function(){
				var tips=art.dialog.tips("提交中……");
				$.ajax({
					async:false,
					type:'GET',
					url:url,
					success:function(rsObj){
						if(rsObj.response_code=="1"){
							tips=art.dialog.tips("删除成功");
							setTimeout(function(){
								window.location.reload();
							},1000);
						}else{
							art.dialog.alert(rsObj.response_message);
						}
					},
					cache:false
				});
			},
			cancel:true
		});
	}
</script>
{% endblock %}